package com.foreveross.proxyip.infra.impl;

import java.sql.Connection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.foreveross.proxyip.entity.HistoryIpEntity;
import com.foreveross.proxyip.infra.base.ddd.repository.EntityHibernateRepository;
import com.foreveross.proxyip.infra.base.ddd.repository.IBaseRepository;
import com.foreveross.proxyip.infra.base.ddd.repository.IJdbcRepository;

@Service
public class HistoryRepositoryImpl extends EntityHibernateRepository implements IBaseRepository{

	@Autowired
	IJdbcRepository jdbcRepository ;
	
	/**
	 * 保存数据
	 * @param list
	 * @return
	 * @throws Exception 
	 */
	@Override
	public void transSaveList(List list) {
		Connection conn = null;
		boolean currAutoCommit = true;
		try{
			conn =  jdbcRepository.getConnection();
			currAutoCommit = conn.getAutoCommit();
			conn.setAutoCommit(false);
			this.jdbcRepository.saveList(conn,list, HistoryIpEntity.class);
			conn.commit();
		}catch(Exception e){
			logger.info("存入数据出错:" + e);
		}finally{
		if(conn!=null){
			try {
				conn.setAutoCommit(currAutoCommit);
				conn.close();
			} catch (Exception e) {
				logger.info("存入数据出错:" + e);
			}
			
		}
	}
	}
	
	

}
